package com.auxgroup.smarthome.inner.controller;

import com.auxgroup.bridge.app.inner.dto.DeviceRepairDto;
import com.auxgroup.bridge.app.inner.vo.DeviceRepairVo;
import com.auxgroup.smarthome.inner.service.DeviceRepairService;
import com.auxgroup.smarthome.utils.PageContent;
import com.auxgroup.smarthome.web.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 一键报修相关API
 * Created by lixiaoxiao on 17-8-7.
 */
@Api(description = "一键报修", tags = "一键报修")
@RestController
public class DeviceRepairController {

    @Autowired
    private DeviceRepairService deviceRepairService;

    @ApiOperation(value = "上报一键报修", notes = "一键报修--上报一键报修")
    @RequestMapping(value = "/device_repair", method = RequestMethod.POST)
    public ApiResponse addDeviceRepairList(@RequestBody DeviceRepairDto deviceRepairDto) {
        return deviceRepairService.addDeviceFault(deviceRepairDto);
    }

    @ApiOperation(value = "后台一键报修列表", notes = "一键报修--获取一键报修列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "报修ID/设备MAC/SN/用户名/手机号", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "integer", required = false),
            @ApiImplicitParam(name = "size", value = "分页大小", paramType = "query", dataType = "integer", required = false),
    })
    @RequestMapping(value = "/device_repair", method = RequestMethod.GET)
    public ApiResponse<PageContent<DeviceRepairVo>> getDeviceRepairList(@RequestParam(required = false) String keyword,
                                                                        @RequestParam(defaultValue = "0", required = false) Integer page,
                                                                        @RequestParam(defaultValue = "5", required = false) Integer size) {
        return ApiResponse.ok(deviceRepairService.findDeviceRepairList(keyword, page, size));
    }

}